Skip to content

feat(fwss): pay one-time fees as they arise on FilecoinPayV2 - #677

Open
CodeWarriorr wants to merge 20 commits into
feat/filecoin-pay-v2from
feat/fwss-pay-v2-pieces-scheduled-remove
Open

CodeWarriorr wants to merge 20 commits into
feat/filecoin-pay-v2from
feat/fwss-pay-v2-pieces-scheduled-remove

Conversation

@CodeWarriorr

@CodeWarriorr CodeWarriorr commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

FilecoinPayV2 lets FWSS lock and disburse from the payer's balance without a grant, so v2 data sets don't need a lifecycle reserve to fund one-time fees. The PDP rail keeps only the terminate fee locked, and every other fee goes to the payee when it arises.

Part of #669

What's changed

  • Creation locks the terminate fee and pays the creation fee to the payee in the same CREATE_RAIL script, instead of locking $0.50
  • piecesScheduledRemove on v2 pays its fee with lock + disburse on the PDP rail (LibRailsV2.chargeOnPdpRail), with no refill
  • v2 data sets report the scaled terminate fee as lifecycleReserveBalance and keep pendingOneTimePayments at zero, so held payment in settleRail (Add settleRail #673) is still available minus the reserve
  • The PDP rail nonce comes from LibRailsV2.pdpRailNonce, shared by createRails and the fee charge

No ABI or storage change.

Each integration step can move its call sites to v2 without touching the facet constructors again, and the build stays green while v1 is still in use.
forge lint fails on a fresh build once FWSS compiles filecoin-pay-v2: RailId.sol shadows exists() with a return variable of the same name.
New data sets go to FilecoinPayV2 only, while existing ones keep their FilecoinPayV1 rails until they drain. dataSetCreated now opens the rails and locks the lifecycle reserve and CDN lockups in one executeScript call scoped to CREATE_RAIL, and checks the old funding threshold against the payer's v2 balance. The v1 allowance checks have no v2 counterpart, so they and their errors go.

Each rail role gets its own nonce, so the cache-miss and CDN rails stay apart when the payee is the FilBeam beneficiary. The PDP rail carries FLAG_CALLBACK for the IRailV2 settlement that follows.

_createRails is virtual so tests can keep creating v1 data sets through a test-only module and still cover the flows after creation on them.
Synapse and other clients can't all move to FilecoinPayV2 at the FWSS
upgrade, so creation keeps FilecoinPayV1 by default and existing clients
see no change. A client opts a new data set into FilecoinPayV2 with the
withPayV2 metadata key, which the payer signs with the rest of the
metadata, the same way withCDN turns on the CDN rails.

This brings back the FilecoinPayV1 creation path and its four errors,
and drops the test-only module that recreated it.
The opt-in paragraph read as if the rest of the spec applied to
FilecoinPayV2 rails too. Also note that its CREATE_RAIL grant has no
allowance caps.
The team settled on packing the payment version into storage terms
instead of a signed metadata key, which costs a stored metadata entry
on every v2 data set. StorageTerms gains a uint8 payVersion (0 is
FilecoinPayV1, 1 is FilecoinPayV2) in a free byte of the record's first
slot, so record zero and existing records stay on v1. Terms with a
nonzero version hash under their own type, so v1 ids do not move and
the same prices on each version get their own id.
The v2 path read the payer's balance and checked the v1 funding
threshold, including fee headroom, before running the script.
FilecoinPayV2 already reverts the script when a lock does not fit, so
the extra call and the headroom check go, as asked in review.
…ated

# Conflicts:
#	service_contracts/src/lib/FWSSFilecoinPayV2.sol
No terms besides record zero are registered on Mainnet or Calibnet, so a
single formula costs no released id and drops the v1 branch.
FilecoinPayV2 refills address the PDP rail by its nonce, so the
nonce moves next to the other FilecoinPayV2 helpers. The refill
threshold becomes a pure function both payment versions can use.
On a FilecoinPayV2 data set the lifecycle reserve is a lock on the
PDP rail, so the refill locks the shortfall there. It adds rather
than sets, because the rail's available balance also holds payment
the settlement callback keeps for open proving periods.
// The PDP rail's available balance also holds settled payment, so add the shortfall, never set it.
address token = LibStorageTerms.getRecord(info.storageTermsId).token;
_lockOnPdpRail(dataSetId, token, payer, info.payee, replenished - reserveBalance);
info.lifecycleReserveBalance = replenished;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing this, the "lifecycle reserve" only needs to contain the termination fee. All other fees can be assessed as we go. Then don't need to maintain lifecycleReserveBalance (or replenish) because the fixed lockup will always be the scaled TERMINATE_FEE.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. @Filip-L this drops topUpLifecycleReserve for v2, #673 should work as is since the reserve is just the terminate fee now

LibRails is typed on FilecoinPayV1, so the v2 rail code gets its own library,
called the same way as LibRails.createRails.
…' into feat/fwss-pay-v2-pieces-scheduled-remove

# Conflicts:
#	service_contracts/src/modules/FWSSDataSetModule.sol
Base automatically changed from feat/fwss-pay-v2-dataset-created to feat/filecoin-pay-v2 November 26, 2026 11:05
createRails now derives the PDP nonce through pdpRailNonce, so one place computes it. FWSSFilecoinPayV2 keeps only the FilecoinPayV2 address and _isV1Rail.
FilecoinPayV2 lets FWSS lock and disburse from the payer's balance without a
grant, so v2 data sets no longer need a lifecycle reserve to fund one-time
fees. The PDP rail keeps only the scaled terminate fee locked. Creation pays
its fee in the rail script, and scheduling piece removals pays its fee with a
lock and a disburse on the PDP rail. Nothing waits in pendingOneTimePayments,
so the v2 refill path and LibRails.replenishedReserve go away.
@CodeWarriorr CodeWarriorr changed the title feat(fwss): refill the lifecycle reserve on FilecoinPayV2 when scheduling removals feat(fwss): pay one-time fees as they arise on FilecoinPayV2 Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review

Development

Successfully merging this pull request may close these issues.

2 participants